<?php
namespace app\mall_back\controller;

use think\admin\Controller;

class Dispose extends Controller{
    const PROTOCOLS = ['about-us', 'service-protocol', 'consumer-protocol', 'privacy-protocol'];

    /**
     * 部分配置管理
     * @auth true
     */
    public function index(){
        if (request()->isPost()){
            $customer_service_qq = request()->param('customer_service_qq','');
            $customer_service_phone = request()->param('customer_service_phone','');
            $customer_service_time = request()->param('customer_service_time','');
            $withdrew_rate = request()->param('withdrew_rate','');
            $integral_rate = request()->param('integral_rate','');
            $commission_rate = request()->param('commission_rate','');
            $invite_register_integral = request()->param('invite_register_integral','');
            $postData = request()->post();
            sysdata('integral_duihuan_num',$postData['integral_duihuan_num']);
            sysdata('duihuan_money_num',$postData['duihuan_money_num']);
            sysdata('signIn_give_integral',$postData['signIn_give_integral']);
            sysdata('recharge_integral_commission_rate',$postData['recharge_integral_commission_rate']);

            sysdata('turntable1_integral',$postData['turntable1_integral']);
            sysdata('turntable2_integral',$postData['turntable2_integral']);


            sysdata('customer_service_qq',$customer_service_qq);
            sysdata('customer_service_phone',$customer_service_phone);
            sysdata('customer_service_time',$customer_service_time);
            sysdata('withdrew_rate',$withdrew_rate);
            sysdata('integral_rate',$integral_rate);
            sysdata('commission_rate',$commission_rate);
            sysdata('invite_register_integral',$invite_register_integral);
            $this->success('修改成功');
        }
        $customer_service_qq = sysdata('customer_service_qq')?:'';
        $customer_service_phone = sysdata('customer_service_phone')?:'';
        $customer_service_time = sysdata('customer_service_time')?:'';
        $withdrew_rate = sysdata('withdrew_rate')?:'';
        $integral_rate = sysdata('integral_rate')?:'';
        $commission_rate = sysdata('commission_rate')?:'';
        $invite_register_integral = sysdata('invite_register_integral')?:'';

        $integral_duihuan_num = sysdata('integral_duihuan_num');
        $duihuan_money_num = sysdata('duihuan_money_num');
        $signIn_give_integral = sysdata('signIn_give_integral')?:'';
        $recharge_integral_commission_rate = sysdata('recharge_integral_commission_rate')?:'';


        $arr = array(
            'customer_service_qq' => $customer_service_qq,//客服在线请求
            'customer_service_phone' => $customer_service_phone,//客服电话
            'customer_service_time' => $customer_service_time,//客服在线时间
            'withdrew_rate' => $withdrew_rate,//提现手续费
            'integral_rate' => $integral_rate,//积分返还比例
            'commission_rate' => $commission_rate,//分佣比例(%)
            'invite_register_integral' => $invite_register_integral,//拉新注册返积分(个),
            'integral_duihuan_num'=>$integral_duihuan_num,
            'duihuan_money_num'=>$duihuan_money_num,
            'signIn_give_integral'=>$signIn_give_integral,
            'recharge_integral_commission_rate'=>$recharge_integral_commission_rate,
             'turntable1_integral'=>sysdata('turntable1_integral')?:'',
             'turntable2_integral'=>sysdata('turntable2_integral')?:'',
        );
        return view('/dispose/index',$arr);
    }

    //用户充值协议
    public function recharge_agreement_edit(){
        if (request()->isPost()){
            $content = request()->param('content','');
            sysdata('recharge_agreement_edit',$content);
            $this->success('修改成功');
        }
        $recharge_agreement_edit = sysdata('recharge_agreement_edit')?:'';
        return view('/dispose/recharge_agreement_edit',array('recharge_agreement_edit'=>$recharge_agreement_edit));
    }

    public function manage()
    {
        $key   = request()->param('key', '');
        $title = request()->param('title', '');
        if (!in_array($key, static::PROTOCOLS)) {
            $this->success('不支持的协议参数！');
        }

        if (request()->isPost()) {
            $content = request()->param('content', '');
            sysdata($key, ['title' => $title, 'content' => $content]);
            $this->success('修改成功');
        }

        $result = sysdata($key) ?: ['title' => '', 'content' => ''];

        return view('/dispose/common_edit', array_merge(['key' => $key], $result));
    }
}